package com.example.demo.his.leetcode;

/**
 * @auther zzc
 * @date 2021 03 23
 */
public class 合并二叉树 {
    public static void main(String[] args) {
        TreeNode t1 = new TreeNode();
        TreeNode t2 = new TreeNode();
        merage(t1, t2);

    }

    private static TreeNode merage(TreeNode t1, TreeNode t2) {
        if (t1 == null) {
            return t2;
        }
        if (t2 == null) {
            return t1;
        }
        t1.left = merage(t1.left, t2.left);
        t1.right = merage(t1.right, t2.right);
        t1.val += t2.val;
        return t1;
    }


    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
}
